iT邦幫忙

0

DAY12:用pipeline來做文字接龍

  • 分享至 

  • xImage
  •  

前面我們都是使用model.generate來做文字接龍,雖然這樣能掌握完整流程(例如token編碼、解碼、Top-k抽樣等),但在實務上,如果只是要快速建立聊天或文字生成功能,其實Hugging Face提供的pipeline更簡單。


pipeline是什麼?
pipeline是Hugging Face的高階工具,用來封裝模型的常見任務。
它就像一條自動化生產線,把輸入的文字丟進去→模型幫你跑→直接拿結果。
使用pipeline可以省略將文字轉成token ID再轉回來的過程,不需要再手動轉成token ID、也不用decode。

pipeline任務包括:

  1. "text-generation":文字生成(聊天、故事、摘要)
  2. "text-classification":文本分類
  3. "translation":翻譯
  4. "automatic-speech-recognition":語音辨識
  5. "image-to-text":圖像轉文字

實作pipeline版的多輪對話
https://ithelp.ithome.com.tw/upload/images/20251016/20169372sajUfs1LEz.png
https://ithelp.ithome.com.tw/upload/images/20251016/201693724A1K72txIT.png


圖片
  熱門推薦
圖片
{{ item.channelVendor }} | {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言